using System;
using System.Diagnostics;
using System.Globalization;

namespace Atomic.Libraries.Physics.Units
{
	[Serializable]
	[DebuggerDisplay("{DebuggerDisplay}")]
	public class Velocity
	{
		private double value;
		//private IUnitSystem system;

		private Velocity(double value)
		{
			this.value = value;
		}

		public static Velocity FromUnit(IUnitSystem system, double value)
		{
			return new Velocity(value / (system.LengthScaling / system.TimeScaling));
		}

		public static Velocity FromAngstromPerSecond(double value)
		{
			return FromUnit(UnitSystem.AtomicSystem, value);
		}

		public static Velocity FromMeterPerSecond(double value)
		{
			return FromUnit(UnitSystem.InternationalSystem, value);
		}
		
		public double ToUnit(IUnitSystem system)
		{
			return value * system.LengthScaling / system.TimeScaling;
		}

		public double ToAngstromPerSecond()
		{
			return ToUnit(UnitSystem.AtomicSystem);
		}

		public double ToMeterPerSecond()
		{
			return ToUnit(UnitSystem.InternationalSystem);
		}

		public static implicit operator double(Velocity value)
		{
			return value.ToAngstromPerSecond();
		}

		public static implicit operator Velocity(double value)
		{
			return FromAngstromPerSecond(value);
		}

		private string DebuggerDisplay
		{
			get
			{
				return string.Format(CultureInfo.InvariantCulture, "{0} Å/s = {1} m/s", ToAngstromPerSecond(), ToMeterPerSecond());
			}
		}
	}
}
